package com.example.demo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;

/**
 * Created with IntelliJ IEDA.
 * Description:
 * User:86186
 * Date:2023-05-30
 * Time:23:15
 */

//@RestController
//@RestController = @Controller + @ResponseBody

@Controller //当前类为控制器
@ResponseBody //返回的是数据，而非页面
public class TestController {
    @Value("${mytext}")
    private String mytext;

    @Value("${mytext2}")
    private String mytext2;

    @Value("${mystring}")
    private String mystring;

    @Value("${mystring2}")
    private String mystring2;

    @Value("${mystring3}")
    private String mystring3;

    @Autowired
    private Student student;

    @PostConstruct
    private void postConstruct(){
//        System.out.println(student);
//        System.out.println("mystring1: " + mystring);
//        System.out.println("mystring1: " + mystring2);
//        System.out.println("mystring1: " + mystring3);

    }
    @RequestMapping("/hi")//url路由注册，用来完成映射的
    public String sayHi(String name){
        //为空或为null，默认值处理
//        if (name == null || name.equals("")){
        //如果没有长度的情况下,和上面的if的效果相等
        if (!StringUtils.hasLength(name)){
            name = "悟空";
        }
        return "你好:" + name;

    }
    @RequestMapping("/getMytext")
    public String getConfig(){
        return "你好: " + mytext;
    }
}

